package com.yunshang.ysmall.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.yunshang.ysmall.mapper.ProductImgListMapper;
import com.yunshang.ysmall.mapper.ProductInfoMapper;
import com.yunshang.ysmall.mapper.ProductTypeInfoMapper;
import com.yunshang.ysmall.model.ProductImgList;
import com.yunshang.ysmall.model.ProductInfo;
import com.yunshang.ysmall.model.ProductTypeInfo;
import com.yunshang.ysmall.service.ProductService;

@Service
public class ProductServiceImpl implements ProductService {
	
	@Resource
	ProductTypeInfoMapper productTypeInfoMapper;
	@Resource
	ProductInfoMapper productInfoMapper;
	@Resource
	ProductImgListMapper productImgListMapper;

	@Override
	public boolean addProduct(ProductInfo productInfo) {
		// TODO Auto-generated method stub
		productInfoMapper.insert(productInfo);
		return true;
	}

	@Override
	public List<ProductInfo> getProductListByMap(Map params) {
		// TODO Auto-generated method stub
		return productInfoMapper.getProductListByMap(params);
	}

	@Override
	public boolean updateProduct(ProductInfo productInfo) {
		// TODO Auto-generated method stub
		return productInfoMapper.updateByPojo(productInfo) > 0 ? true : false;
	}

	
	
	@Override
	public boolean addProductType(String typeName) {
		// TODO Auto-generated method stub
		ProductTypeInfo productTypeInfo = new ProductTypeInfo();
		productTypeInfo.setTypeName(typeName);
		return productTypeInfoMapper.insert(productTypeInfo) > 0 ? true : false;
	}

	@Override
	public boolean delProductType(Integer typeId) {
		// TODO Auto-generated method stub
		return productTypeInfoMapper.deleteByPrimaryKey(typeId) > 0 ? true : false;
	}

	@Override
	public List<ProductTypeInfo> getTypeList() {
		// TODO Auto-generated method stub
		return productTypeInfoMapper.getTypeList();
	}

	@Override
	public ProductInfo getProductById(String productId) {
		// TODO Auto-generated method stub
		return productInfoMapper.selectByProId(productId);
	}

	@Override
	public List<ProductImgList> getImgListByProId(String productId) {
		// TODO Auto-generated method stub
		return productImgListMapper.selectByProId(productId);
	}

	@Override
	public boolean saveProductImg(ProductImgList productImgList) {
		// TODO Auto-generated method stub
		return productImgListMapper.insert(productImgList) > 0 ? true : false;
	}

	@Override
	public boolean deleteProduct(String productId) {
		// TODO Auto-generated method stub
		return productInfoMapper.delete(productId) > 0 ? true : false;
	}

	
}
